#ifndef BACKWIDGET_H
#define BACKWIDGET_H

#include <QWidget>
#include <QHash>
#include <QEvent>
#include <QMessageBox>
#include "mqttwidget.h"
#include "QtQmqtt"

namespace Ui {
class BackWidget;
}


class BackWidget : public QWidget
{
    Q_OBJECT

public:
    explicit BackWidget(QWidget *parent = nullptr);
    ~BackWidget();

    void setClient(QMQTT::Client *client);

    QMap<int,MqttWidget*> getMqttWidgets(); //需要考虑到文件类型、解析
    void saveMqttWidgets();
    void addMqttWidget(const QPoint &pos, MqttData data);   //需要考虑到类型

signals:
    void publishMessage(QMQTT::Message);

public slots:
    void receivedMessage(QMQTT::Message message);

protected:
    void focusInEvent(QFocusEvent *e);
    void focusOutEvent(QFocusEvent *e);

    void mousePressEvent(QMouseEvent *event);
private:
    Ui::BackWidget *ui;
    bool haveEdit = 0;          //标识下面的映射数据是否被编辑
    QHash<int,MqttWidget*> mqttWidgetMap;    //控件容器
    void showMenu(const QPoint &pos);
    bool removMqttWidget(int id);
    void removMqttWidgets(QList<int> idList);
    QMQTT::Client *mqttClient = nullptr;

};

#endif // BACKWIDGET_H
